package com.hup.minicontroller.client.mvp;

import androidx.core.util.Consumer;

import com.hup.minicontroller.common.constant.ControlActionConstant.FunctionButton;
import com.hup.minicontroller.common.constant.NetConstant.ConnectType;
import com.hup.minicontroller.common.model.dto.FullScreenTouchRequest;
import com.hup.minicontroller.common.model.dto.TouchPadTouchRequest;

import java.util.ArrayList;

/**
 * (lan,蓝牙)client客户端网络处理类,实现功能:
 * .模块的启动/停止,等生命周期
 * .处理界面触发的功能,并通知客户端
 * .接收客户端数据并通知app,ui更新,实现用户控制
 */
public interface IClientHandler {

    ConnectType getConnectType();

    void switchClient(boolean isConnect);

    void onControlConfigChanged();

    void onFunctionButton(FunctionButton button);

    void onFullScreenTouch(FullScreenTouchRequest fullScreenTouch);

    void onTouchPadTouch(TouchPadTouchRequest touchPadTouch);

    void doTerminate();

    /**
     * 拼接网速字符串,未连接时不拼接内容
     */
    void getSpeedText(StringBuilder sb);

    class ClientHandlerList extends ArrayList<IClientHandler> {
        public void forEach(Consumer<IClientHandler> consumer) {
            for (IClientHandler handler : this) {
                consumer.accept(handler);
            }
        }

        public IClientHandler get(ConnectType connectType) {
            for (IClientHandler handler : this) {
                if (handler.getConnectType() == connectType) {
                    return handler;
                }
            }
            throw new IllegalArgumentException("不存在handler?");
        }
    }

}
